package cn.dengqiang.user.controller;

import cn.dengqiang.basic.util.AjaxResult;
import cn.dengqiang.basic.util.PageList;
import cn.dengqiang.user.domain.LoginInfo;
import cn.dengqiang.user.query.LoginInfoQuery;
import cn.dengqiang.user.service.ILoginInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController   //=@ResponseBody+@Controller
@RequestMapping("/loginInfo")

@Api(tags = "店铺接口",description = "店铺接口详细描述")
public class LoginInfoController {

    @Autowired
    private ILoginInfoService loginInfoService;

    @PutMapping
    public AjaxResult save(@RequestBody LoginInfo loginInfo){
        try {
            if (loginInfo.getId()==null){
                loginInfoService.add(loginInfo);
            }else {
                loginInfoService.update(loginInfo);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("保存失败"+e.getMessage());
        }
    }




    @ApiOperation(value = "删除",notes = "根据id删除一条数据")
    @DeleteMapping("/{id}")
    public AjaxResult del(@PathVariable("id") Long id){
        try {
            loginInfoService.del(id);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
           return new AjaxResult("删除失败!"+e.getMessage());
       }
    }

    @ApiOperation(value = "查询",notes = "根据id查询一条数据")
    @GetMapping("/{id}") //根据id查询
    public LoginInfo getById(@PathVariable("id") Long id){
        return loginInfoService.getById(id);
    }

    @ApiOperation(value = "查询",notes = "查询所有信息")
    @GetMapping //loginInfo 查询所有
    public List<LoginInfo> getAll(){
        return loginInfoService.getAll();
    }

    @ApiOperation(value = "查询",notes = "分页查询")
    @PostMapping//分页查询
    public PageList<LoginInfo> list(@RequestBody LoginInfoQuery query){
        return loginInfoService.queryPage(query);
    }

}
